package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.db.domain.system.MpClientSubOrder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.service.IMpClientSubOrderService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 子订单Controller
 * 
 * @author ruoyi
 * @date 2022-08-01
 */
@Api(value = "子订单",tags ="子订单")
@RestController
@RequestMapping("/sub/order")
public class MpClientSubOrderController extends BaseController
{
    private static Logger log = LoggerFactory.getLogger(MpClientSubOrderController.class);
    @Autowired
    private IMpClientSubOrderService mpClientSubOrderService;

    /**
     * 查询子订单列表
     */
    @ApiOperation(value = "查询子订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientSubOrder",value="子订单",paramType="form")
    })
    @RequiresPermissions("system:order:list")
    @GetMapping("/list")
    public TableDataInfo list(MpClientSubOrder mpClientSubOrder)
    {
        try {
            startPage();
            List<MpClientSubOrder> list = mpClientSubOrderService.selectMpClientSubOrderList(mpClientSubOrder);
            return getDataTable(list);
        }catch (Exception e){
            log.error("子订单发生异常",e);
        }
        return null;
    }

    /**
     * 导出子订单列表
     */
    @ApiOperation(value = "导出子订单列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientSubOrder",value="子订单",dataType="MpClientSubOrder")
    })
    @RequiresPermissions("system:order:export")
    @Log(title = "子订单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response,@RequestBody MpClientSubOrder mpClientSubOrder)
    {
        try {
            List<MpClientSubOrder> list = mpClientSubOrderService.selectMpClientSubOrderList(mpClientSubOrder);
            ExcelUtil<MpClientSubOrder> util = new ExcelUtil<MpClientSubOrder>(MpClientSubOrder.class);
            util.exportExcel(response, list, "子订单数据");
        }catch (Exception e){
            log.error("子订单发生异常",e);
        }
    }

    /**
     * 获取子订单详细信息
     */
    @ApiOperation(value = "获取子订单详细信息")
    @ApiImplicitParam(name="subOrderId",value="子订单")
    @RequiresPermissions("system:order:query")
    @GetMapping(value = "/{subOrderId}")
    public AjaxResult getInfo(@PathVariable("subOrderId") String subOrderId)
    {
        try {
            return AjaxResult.success(mpClientSubOrderService.selectMpClientSubOrderBySubOrderId(subOrderId));
        }catch (Exception e){
            log.error("子订单发生异常",e);
        }
        return AjaxResult.error("子订单异常");
    }

    /**
     * 新增子订单
     */
    @ApiOperation(value = "新增子订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientSubOrder",value="子订单",dataType="MpClientSubOrder")
    })
    @RequiresPermissions("system:order:add")
    @Log(title = "子订单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MpClientSubOrder mpClientSubOrder)
    {
        try {
            int i=mpClientSubOrderService.insertMpClientSubOrder(mpClientSubOrder);
            return toAjax(i);
        }catch (Exception e){
            log.error("新增子订单发生异常",e);
        }
        return AjaxResult.error("子订单异常");
    }

    /**
     * 修改子订单
     */
    @ApiOperation(value = "修改子订单")
    @ApiImplicitParams({
            @ApiImplicitParam(name="mpClientSubOrder",value="子订单",dataType="MpClientSubOrder")
    })
    @RequiresPermissions("system:order:edit")
    @Log(title = "子订单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MpClientSubOrder mpClientSubOrder)
    {
        try {
            int i=mpClientSubOrderService.updateMpClientSubOrder(mpClientSubOrder);
            return toAjax(i);
        }catch (Exception e){
            log.error("修改子订单发生异常",e);
        }
        return AjaxResult.error("子订单异常");
    }

    /**
     * 删除子订单
     */
    @ApiOperation(value = "删除子订单")
    @ApiImplicitParam(name="subOrderIds",value="子订单")
    @RequiresPermissions("system:order:remove")
    @Log(title = "子订单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{subOrderIds}")
    public AjaxResult remove(@PathVariable String[] subOrderIds)
    {
        try {
            int i=mpClientSubOrderService.deleteMpClientSubOrderBySubOrderIds(subOrderIds);
            return toAjax(i);
        }catch (Exception e){
            log.error("删除子订单发生异常",e);
        }
        return AjaxResult.error("子订单异常");
    }
}
